/**
 * 功能描述 表单
 */

define(function (require, exports, module){
	var Form = require("form");
	var aw = require("ajaxwrapper")
	var instance = {
		initComponent: function (params,widget,destnbuilding){
			var pkServicePoint = widget.get("signupform").getValue("servicePoint");
			
			var buildingArr = [];
			
			for(var i=0;i<destnbuilding.length;i++){
				buildingArr.push(destnbuilding[i].orgBuilding.pkOrgBuilding);
			}
			
			var form=new Form({
				autoRender:false,
				model:{
					id : "roomTypeForm",
					defaultButton:false,
					items:[{
						name:"roomType",
						label:"房型",
						type:"select",
						key:"pkRoomType",
						value:"name",
						url: "api/roomtype/query",
						params : function(){
							return {
								fetchProperties : "pkRoomType,name",
								servicePoint: pkServicePoint
							}
						},
						events:{
							"change":function(e){
								var pkRoomType = e.target.value;
								var roomForm = widget.get("roomForm");
								
								aw.ajax({
									url:"api/room/query",
									data:{
										fetchProperties : "pkRoom,code,roomType.pkRoomType,roomType.name",
										"status":"Clear",
										"roomType.pkRoomType":pkRoomType,
										"orgBuilding.pkOrgBuildingIn":buildingArr.join(",")
									},
									dataType:"json",
									success:function(data){
										roomForm.setData("room", data);
									}
								});
							}
						}
					},{
						name:"room",
						label:"房号",
						type:"select",
						key:"pkRoom",
						value:"code"
					}]
				}
			});
			widget.set("roomForm",form);
			return form;
		}
	};
	module.exports = instance;
});